package com.contory.ssn_lgnd.app.maingame;

import java.util.LinkedList;

import com.contory.ssn_lgnd.app.comp.DrawPtr;
import com.contory.ssn_lgnd.app.comp.UpdatePtr;
import com.contory.ssn_lgnd.framework.Pool;
import com.contory.ssn_lgnd.framework.Pool.PoolObjectFactory;
import com.contory.ssn_lgnd.framework.gl.Animation;
import com.contory.ssn_lgnd.framework.gl.SpriteBatcher;

public class TextureEffectGroup implements UpdatePtr, DrawPtr{
	LinkedList<TextureEffectAnimation> effectList;
	Pool<TextureEffectAnimation> pool;
	
	public TextureEffectGroup(){
		effectList = new LinkedList<TextureEffectAnimation>();
		PoolObjectFactory<TextureEffectAnimation> factory = new PoolObjectFactory<TextureEffectAnimation>() {
			@Override
			public TextureEffectAnimation createObject() {
				return new TextureEffectAnimation();
			}
		};
		pool = new Pool<TextureEffectAnimation>(factory, 100);
	}
	
	public void addEffect(Animation ani, int type, float x , float y, float w, float h){
		TextureEffectAnimation chd = pool.newObject();
		chd.setInit(ani, type, x, y, w, h);
		effectList.add(chd);
	}

	@Override
	public void draw(SpriteBatcher batcher) {
		for(int i = 0; i < effectList.size(); i++)
			effectList.get(i).draw(batcher);
	}

	@Override
	public void update(float deltaTime) {
		for(int i = 0; i < effectList.size(); i++){
			TextureEffectAnimation chd = effectList.get(i);
			chd.update(deltaTime);
			if(chd.getAniEndBool()){
				pool.free(chd);
				effectList.remove(chd);
			}
		}
	}
}
